package tmpl

var tp2mysql = map[string]string{
	"^date$":                      "datetime",
	"^datetime$":                  "datetime",
	"^timestamp$":                 "datetime",
	"^decimal$":                   "decimal",
	"^float$":                     "float",
	"^int$":                       "int",
	"^number\\([1-2]{1}\\)$":      "tinyint",
	"^number\\([3-9]{1}\\)$":      "int",
	"^number\\(10\\)$":            "int",
	"^number\\(1[1-9]{1}\\)$":     "bigint",
	"^number\\(2[0-9]{1}\\)$":     "bigint",
	"^number\\((\\d+),(\\d+)\\)$": "decimal(*)",
	"^varchar\\((\\d+)\\)$":       "varchar(*)",
	"^varchar2\\((\\d+)\\)$":      "varchar(*)",
	"^string$":                    "tinytext",
	"^text$":                      "text",
	"^longtext$":                  "longtext",
	"^clob$":                      "longtext",
}

var tp2oracle = map[string]string{
	"bigint":            "number(19)",
	"binary":            "raw",
	"bit":               "raw", //长度正确为（n/8）
	"blob":              "blob",
	"boolean":           "char(1)",
	"bool":              "char(1)",
	"char":              "char",
	"character":         "character",
	"character varying": "character varying",
	"date":              "date",
	"datetime":          "timestamp",
	"decimal":           "number",
	"dec":               "number",
	"double":            "binary_double",
	"double precision":  "binary_double",
	"fixed":             "number",
	"float":             "binary_double",
	"float4":            "binary_double",
	"float8":            "binary_double",
	"int":               "number",
	"integer":           "number",
	"int1":              "number(3)",
	"int2":              "number(5)",
	"int3":              "number(7)",
	"int4":              "number(10)",
	"int8":              "number(19)",
	"longblob":          "blob",
	"longtext":          "clob",
	"long varbinary":    "blob",
	"long":              "clob",
	"long varchar":      "clob",
	"mediumblob":        "blob",
	"mediumint":         "number(7)",
	"mediumtext":        "clob",
	"middleint":         "number(7)",
	"nchar":             "nchar",
	"nvarchar":          "nvarchar2",
	"numeric":           "number",
	"real":              "binary_double",
	"smallint":          "number(5)",
	"text":              "clob",
	"time":              "timestamp",
	"timestamp":         "timestamp",
	"tinyblob":          "raw(255)",
	"tinyint":           "number(3)",
	"tinytext":          "varchar2(255)",
	"varbinary":         "raw",
	"varchar":           "varchar2",
	"year":              "number(4)",
}

var def2mysql = []map[string]string{
	{
		"^$":                  "",
		"^-$":                 "default '-'",
		"^seq$":               "",
		"^current_timestamp$": "default current_timestamp",
		"^sysdate$":           "default current_timestamp",
		"^([0-9]+)$":          "default *",
	},
	{
		"^(.+)$": "default '*'",
	},
}

var def2oracle = []map[string]string{
	{
		"^$":                  "",
		"^-$":                 "default '-'",
		"^seq$":               "",
		"^current_timestamp$": "default sysdate",
		"^sysdate$":           "default sysdate",
		"^([0-9]+)$":          "default *",
	},
	{
		"^(.+)$": "default '*'",
	},
}

var any2code = map[string]string{
	"^date$":                      "time.Time",
	"^datetime$":                  "time.Time",
	"^timestamp$":                 "time.Time",
	"^decimal$":                   "types.Decimal",
	"^float$":                     "types.Decimal",
	"^int$":                       "int",
	"^number\\([1-2]{1}\\)$":      "int",
	"^number\\([3-9]{1}\\)$":      "int",
	"^number\\(10\\)$":            "int",
	"^number\\(1[1-9]{1}\\)$":     "int64",
	"^number\\(2[0-9]{1}\\)$":     "int64",
	"^number\\((\\d+),(\\d+)\\)$": "types.Decimal",
	"^varchar\\(\\d+\\)$":         "string",
	"^varchar2\\(\\d+\\)$":        "string",
	"^string$":                    "string",
	"^text$":                      "string",
	"^longtext$":                  "string",
	"^clob$":                      "string",
	//mysql ?
}

var keywordSubMatch = `\b%s\(([\w\s-:#,|/\p{Han}]+)\)`

var keywordMatch = []string{"^\\w*%s\\w*$", ",\\w*%s\\w*,", "^\\w*%s\\w*,", ",\\w*%s\\w*$"}

var cons = map[string][]string{
	"pk": {"\\bpk\\b"},
	//"seq":   {"\\bseq\\b"},
	"di":    {"\\bdi\\b"},
	"dn":    {"\\bdn\\b"},
	"sl":    {"\\bsl(\\([\\w,]+\\)|\\b)"},
	"slm":   {"\\bslm(\\([\\w,]+\\)|\\b)"},
	"rd":    {"\\brd(\\([\\w,]+\\)|\\b)"},
	"cb":    {"\\bcb(\\([\\w,]+\\)|\\b)"},
	"ta":    {"\\bta(\\([\\w,]+\\)|\\b)"},
	"cc":    {"\\bcc(\\(\\w+\\)|\\b)"},
	"idx":   {"\\bidx(\\(([\\w]+)[,]?([\\d]?)\\)|\\b)"},
	"unq":   {"\\bunq(\\(([\\w]+)[,]?([\\d]?)\\)|\\b)"},
	"d":     {"\\bd(\\([0-9]*\\)|\\b)"},
	"c":     {"\\bc(\\([\\w,:#]+\\)|\\b)"},
	"u":     {"\\bu(\\([\\w,:#]+\\)|\\b)"},
	"r":     {"\\br(\\([\\w,:#]+\\)|\\b)"},
	"l":     {"\\bl(\\([\\w,:#]+\\)|\\b)"},
	"q":     {"\\bq(\\([\\w,:#]+\\)|\\b)"},
	"sort":  {"\\bsort(\\((asc|desc)[,]?([\\d]?)\\)|\\b)"},
	"order": {"\\border(\\((asc|desc)[,]?([\\d]?)\\)|\\b)"},
	"*":     {"\\b%s\\b"},
	"seq":   {"\\bseq(\\(([\\w]+)[,]?([\\d]?)[,]?([\\d]?)\\)|\\b)"},
}

var IsNull = map[string]string{
	"否":   "not null",
	"N":   "not null",
	"NO":  "not null",
	"是":   "",
	"":    "",
	"Y":   "",
	"YES": "",
}

var IsMDNull = map[string]string{
	"NO":  "否",
	"N":   "否",
	"n":   "否",
	"no":  "否",
	"YES": "是",
	"yes": "是",
	"Y":   "是",
	"y":   "是",
}
